package com.xuelang.pipeline.artifact.entry.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.UserService;
import com.xuelang.pipeline.artifact.app.harborv2.request.CreateHarborUserRequest;
import com.xuelang.pipeline.artifact.app.harborv2.request.SearchUserQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.SearchUserResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * HarborV2 项目下用户原生接口web服务
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@RestController("harborV2UserController")
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;
    /**
     * 创建用户
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/users", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createUser(@RequestBody @Valid CreateHarborUserRequest request) {
        return userService.createUser(request);
    }

    /**
     * 通过userName获取用户信息
     *
     * @param query
     * @return
     */
    @GetMapping(value = "/users/search", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<SearchUserResponse>> searchUserByUserName(@ModelAttribute SearchUserQuery query) {
        return userService.searchUserByUserName(query);
    }

    /**
     * 删除用户
     *
     * @param userId
     * @return
     */
    @DeleteMapping(value = "/users/{user_id}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteRepositoryOfAnyFormat(@PathVariable("user_id") String userId) {
        return userService.deleteRepositoryOfAnyFormat(userId);
    }


}
